package ngat.oss.simulation.metrics;

import ngat.oss.simulation.*;
import ngat.phase2.*;

/** Calculates a scoring-model based utility SQM.*/
public class ScoringUtilityCalculator implements UtilityCalculator {

    /** Exec timing and feasibility model.*/
    private ExecutionTimingModel execModel;

    /** Scoring model.*/
    private ScoringModel scoringModel;

    /** Accounting model.*/
    private AccountingModel accountingModel;

    /** Create a ScoringUtilityCalculator using the supplied
     * @param execModel An ExecutionTimingModel.
     * @param scoringModel A ScoringModel.
     * @param accountingModel An AccountingModel.
    */ 
    public ScoringUtilityCalculator(ExecutionTimingModel execModel, 
				     ScoringModel scoringModel,
				     AccountingModel accountingModel) {
	this.execModel = execModel;
	this.scoringModel = scoringModel;
	this.accountingModel = accountingModel;
    }
    
    /** Return the utility for the specified group at time under env and hist (not used).
     * Background are treated as zero as they are NOT required to execute. 
     * Standards are treated as 3 which is how they are currently selected, this may be changed
     * in the future. They are still part of the overall science program.
     */
    public double getUtility(Group group, long time, EnvironmentSnapshot env, ExecutionStatistics hist) {

	Accounts accounts = null;
	try {
	    accounts = accountingModel.getAccounts(group.getFullPath());
	} catch (Exception e) {
	    e.printStackTrace();
	}
	// we can live without the accounts it just decreases the score, should never
	// actually happen though !
	double score = scoringModel.scoreGroup(group, accounts, time, env, hist);

	return score;

    }
    
}
